<template>
   <t-link theme="primary"  @click="handleOpenDialog('update',{ projectId: props.id,sellingPrice:props.sellingPrice,materialDataType:props.materialDataType })">{{ sellingPrice.toFixed(2) }}</t-link>
            
   <custom-dialog
    ref="customDialogRef"
    v-slot="{ formData, readonly }"
    :api-map="{update: updateQuotation}"
    header="*售价"
    @request-success="handleDialogRequestSuccess"
  >
    <t-form-item label="售价" name="sellingPrice" :rules="[{ required: true, message: '请输入售价' }]">
      <t-input-number 
        v-model:value="formData.sellingPrice"
        placeholder="请输入主材售价"
        clearable
        style="width: 100%"
        :min="1"
        :decimal-places="2"
        :readonly="readonly"
      />
    </t-form-item>
  </custom-dialog>

     
 
</template>

<script setup lang="ts">
import { useTemplateRef } from 'vue';

import { updateQuotation } from '@/api/budget/programme';
import CustomDialog from '@/components/custom/dialog/index.vue';

const props = defineProps({
  id: {
    type: String,
    default: '',
  },
  sellingPrice: {
    type: Number,
    required: true,
  },
  materialDataType: {
    type: String,
    default: '',
  }
});

// emits
const emits = defineEmits(['requestSuccess']);

// 自定义材料对话框ref
const customDialogRef = useTemplateRef('customDialogRef');
// 处理打开对话框
const handleOpenDialog = (mode: 'create' | 'read' | 'update', params: Record<string, any>) => {
  customDialogRef.value.open(mode, params);
};
// 处理对话框请求成功
const handleDialogRequestSuccess = (result: Record<string, any>) => {
  console.log(result,'res');
  
  emits('requestSuccess', result);
};

</script>


